from pydantic import BaseModel, Field, root_validator


class _CurrencyModel(BaseModel):
    name: str = Field(..., description="币种名字", max_length=16)
    code: str = Field(..., description="币种code", max_length=3)
    symbol: str = Field(..., description="币种符号", max_length=1)


class AddNewCurrencyModel(_CurrencyModel):
    ...


class UpdateCurrencyRequestModel(_CurrencyModel):
    name: str = Field(None, description="币种名字", max_length=16)
    code: str = Field(None, description="币种code", max_length=3)
    symbol: str = Field(None, description="币种符号", max_length=1)

    @root_validator()
    def validate_root(cls, attrs):
        if not any(attrs):
            raise ValueError("缺失更新参数")
        return attrs
